﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuanLyChungCu_V.BussinessTỉer
{
    class ApartmentManagerService
    {
        
        SQLConnection sql_conn;
        public ApartmentManagerService()
        {
            try
            {
                sql_conn = new SQLConnection(null); // Lay ConnectionString trong DataConnection.xml, neu file khong ton tai thi tao moi va ghi lai ConnectionString
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
        
        public void AddCanHo(int rent , int saleprice , int TangLau)

        {
            QLCCDataContext ctx = new QLCCDataContext();
            ctx.Connection.ConnectionString = sql_conn.ConnectionString;
            ctx.CanHos.InsertOnSubmit(new CanHo
            {
                GiaThue = rent,
                GiaBan = saleprice,

            });
            ctx.SubmitChanges();
        }
        public IList<CanHoDTO> FindApartment(int saleprice)
        {
            QLCCDataContext ctx = new QLCCDataContext();
            ctx.Connection.ConnectionString = sql_conn.ConnectionString;

            var apartment = from p in ctx.CanHos
                        // where p.GiaBan.CompareTo(saleprice)
                         select new CanHoDTO
                         {
                             id = p.idCanHo,
                            rent = p.GiaThue,
                          //  TangLau = p.TangLau,
                            saleprice = p.GiaBan,
                            
                         };
            return apartment.ToList<CanHoDTO>();
        }
    }
}
